package com.sky.mapper;

import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.entity.ShoppingCart;
import com.sky.entity.User;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {
    //根据openid查找用户
    @Select("select * from user where openid=#{id}")
    User selectuserbyopenid(@Param("id") String id);

    int insertuser(User user);
    //查询购物车
    ShoppingCart selectbyconditions(ShoppingCart cart);
    int updatenum(@Param("shoppingCart") ShoppingCart shoppingCart,@Param("num") int num);

    int insertaddshopcart(ShoppingCart shoppingCart);
    @Select("select * from shopping_cart where user_id=#{id}")
    List<ShoppingCart> selectallshopcart(@Param("id") Long id);
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void deleteall(@Param("userId") Long userId);
    int insertorder(Orders order);
    int inserorderdetail(OrderDetail orderDetail);

    /** 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);
    @Select("select * from user where id=#{id}")

    User getById(@Param("id") Long id);
    @Select("select * from orders where status=#{status} and order_time<#{time}")
    List<Orders> selectbytimeoutorder(@Param("status") int status, @Param("time")LocalDateTime time);
    @Select("select * from orders where status=#{status}")
    List<Orders> selectDeliverOrder(int status);

    @Select("select * from orders where id=#{id}")
    Orders getbyid(int id);

    Integer countbymap(Map map);

}
